package com.cwnu.service.impl;

import com.cwnu.entity.Article;
import com.cwnu.entity.PageBean;
import com.cwnu.entity.User;
import com.cwnu.mapper.AdminMapper;
import com.cwnu.mapper.UserMapper;
import com.cwnu.service.AdminService;
import com.cwnu.utils.TokenUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Autowired
    private UserMapper userMapper;
    @Override
    public PageBean<User> getUserList(Integer pageNum, Integer pageSize, String username) {
        // 1、创建pageBean对象
        PageBean<User> pb = new PageBean<>();

        // 2、开启分页查询，使用pageHelper插件
        PageHelper.startPage(pageNum, pageSize);

        // 3、调用mapper
        List<User> as = adminMapper.getUserList(username);
        // page中提供了方法，可以获取总记录条数和当前页数据
        Page<User> p = (Page<User>) as;
        // 把数据填充到pageBean对象中
        pb.setTotal(p.getTotal());
        pb.setItems(p.getResult());
        return pb;
    }

    @Override
    public void deleteUser(Integer userId) {
        userMapper.deleteUser(userId);
    }
}
